<!DOCTYPE html>
<html lang="en" dir="ltr">
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="order_sequence.js" charset="utf-8"></script>
		<script type="text/javascript">
		// 创建行集合
		let lines = [];
		// 创建一个10位的排序生成器
		let orderSeq = new OrderSequence(3);

		let doDemo = () => {
			// 生成整个第一行的序列
			let medianValue = orderSeq.getMedianByAll();
			console.log('first median', medianValue);
			lines.push(medianValue);

			// 生成在第一行之前插入行的序列，此时第一行变为第二行。
			let medianValueBefore = orderSeq.getMedianToHead(medianValue);
			console.log('before first median', medianValueBefore);
			lines.push(medianValueBefore);

			// 生成在第二行之后插入行的序列
			let medianValueAfter = orderSeq.getMedianToTail(medianValue);
			console.log('after second median', medianValueAfter);
			lines.push(medianValueAfter);

			// 生成第一行和第二行之间的序列
			let medianValueBetween = orderSeq.getMedian(medianValueBefore, medianValue);
			console.log('between first and second median', medianValueBetween);
			lines.push(medianValueBetween);

			// 排序后的所有序列
			console.log('sort lines:');
			lines.sort();
			for (let line of lines) {
				console.log(line);
			}
		};
		// 尝试不断往最前一行前添加新行，使用中位数
		let doForHead = () => {
			lines = [];
			let lineSeq = orderSeq.getMedianByAll();
			console.log(lineSeq);
			while (lineSeq != null) {
				lines.push(lineSeq);
				lineSeq = orderSeq.getMedianToHead(lineSeq);
			}
			console.log('sort lines:', lines.length);
			lines.sort();
			for (let line of lines) {
				console.log(line);
			}
		};
		// 尝试不断往最后一行后添加新行，使用1/10位置
		let doForTail = () => {
			lines = [];
			let lineSeq = orderSeq.getFractionByAll(1, 10);
			while (lineSeq != null) {
				lines.push(lineSeq);
				lineSeq = orderSeq.getFractionToTail(lineSeq, 1, 10);
			}
			console.log('sort lines:', lines.length);
			lines.sort();
			for (let line of lines) {
				console.log(line);
			}
		};
		</script>
	</head>
	<body>
	</body>
</html>
